<script setup>


import {getCurrentInstance, ref} from "vue";

const {proxy} = getCurrentInstance();
const taskId = proxy.$route.params.id

import {getTasks} from '@/api/task/tasks'
import FileUpload from "@/components/FileUpload/index.vue";

const taskInfo = ref({})
const getInfo = async () => {
  const res = await getTasks(taskId)
  taskInfo.value = res.data
}
const fileData = ref([])
import {addTaskSub} from '@/api/task/taskSub'
import {ElMessage} from 'element-plus'

const submitFile = async () => {
  taskSubInfo.value.taskId = taskId;
  taskSubInfo.value.filePath = fileData.value[0].url;
  const res = await addTaskSub(taskSubInfo.value)
  if (res.code == 200) {
    ElMessage.success('提交成功')
  }
}
const reset=()=>{
  taskSubInfo.value=null
}
const taskSubInfo = ref({})
getInfo();
</script>

<template>
  <div>
        <el-form :model="taskInfo">
          <el-form-item label="任务名称">
            {{ taskInfo.taskName }}
          </el-form-item>
          <el-form-item label="开始时间">
            {{ taskInfo.createdAt }}
          </el-form-item>
          <el-form-item label="结束时间">
            {{ taskInfo.deadline }}
          </el-form-item>
          <el-form-item label="选择文件">
            <file-upload v-model="fileData">选取文件</file-upload>
          </el-form-item>
          <el-form-item label="提交文件">
            <el-button type="primary" @click="submitFile">提交文件</el-button>
          </el-form-item>
        </el-form>
  </div>
</template>

<style scoped lang="scss">

</style>
